<!DOCTYPE html>
<html>
<head>
<script src=../../resources/js-test.js language="javascript" type="text/javascript"></script>
<title>Testing that searching for text starts at the active selection</title>
</head>
<body>
    <div id="container">
        The _before_selection_ word is before the selection, so we shouldn't be able to find it if span_to_select is selected.
        <br/>
        <span id="span_to_select">The _in_selection_ word is in the selection and we should always be able to find it.</span>
        <br/>
        The _after_selection_ word is after the selection and we should always be able to find that too.
    </div>
<pre id="console" style="visibility: hidden;"></pre>
<script>
function log(message)
{
    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
}

function selectText()
{
    var selection = window.getSelection();
    var range = document.createRange();
    var spanToSelect = document.getElementById('span_to_select');
    range.setStartBefore(spanToSelect);
    range.setEndAfter(spanToSelect);
    selection.addRange(range);
}

if (!window.testRunner)
    testFailed('This test requires the testRunner object');
else {
    shouldBeTrue('testRunner.findString("_before_selection_", [])');
    shouldBeTrue('testRunner.findString("_in_selection_", [])');
    shouldBeTrue('testRunner.findString("_after_selection_", [])');

    debug('Selecting some text. This should make it not possible to find the _before_selection_ word without enabling wrap-around.');
    selectText();

    shouldBeFalse('testRunner.findString("_before_selection_", [])');
    shouldBeTrue('testRunner.findString("_in_selection_", [])');
    shouldBeTrue('testRunner.findString("_after_selection_", [])');
}

document.getElementById("console").style.removeProperty("visibility");

var successfullyParsed = true;
</script>
</body>
</html>
